package org.cdivtc.exam.controller;


import io.swagger.annotations.*;
import org.cdivtc.exam.DTO.StudentAddDTO;
import org.cdivtc.exam.entity.Students;
import org.cdivtc.exam.service.StudentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


import javax.validation.Valid;
import java.util.Map;

/**
 * <p>
 * 学生基本信息表 前端控制器
 * </p>
 *
 * @author xiaogoudashuai
 * @since 2025-03-27
 */

@RestController
@RequestMapping("/api/student")
@Api(tags = "学生管理", description = "学生信息管理相关接口")
public class StudentsController {

    @Autowired
    private StudentsService studentsService;

    @ApiOperation(value = "根据账号和密码进行登录操作，只需要账号和密码。返回个人信息和token字符串",
            notes = "<span style = 'color:red'>模拟操作，密码为明文密码</span>",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account",type = "String",required = true),
            @ApiImplicitParam(name = "password",type = "String",required = true)
    })

    @PostMapping("student/login")
    @ApiParam
    public Map<String, Object> login(@RequestParam String account,
                                     @RequestParam String password) {
        return studentsService.login(account, password);
    }


    /*学生信息修改*/
    @GetMapping("/update")
    @ApiOperation(value = "修改学生信息",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",type = "Integer",required = true),
            @ApiImplicitParam(name = "newPhone",type = "Integer",required = true),
            @ApiImplicitParam(name = "newPassword",type = "Integer",required = true)
    })
    public void updateSecurityInfo(@RequestParam Long id,
                                   @RequestParam String newPhone,
                                   @RequestParam String newPassword) {
        studentsService.updatePhoneAndPassword(id, newPhone, newPassword);
    }


    @GetMapping("/Search")
    @ApiOperation(value = "学生错题信息查询")
    @ApiParam
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current",value = "",
                    defaultValue = "1",dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(name = "size",value = "",
                    dataType = "Integer",paramType = "query",defaultValue = "10"),
            @ApiImplicitParam(name = "condition",value = "",defaultValue = "String",paramType = "query"),
            @ApiImplicitParam(name = "user_type",value = "",dataType = "Integer",required = true)
    })
    public String Search() {
        return "Hello, World!";
    }

    /*考试报名/注册*/
    @PostMapping("/add")
    @ApiOperation(value = "考试报名/注册")
    @ApiResponses({
            @ApiResponse(code = 201, message = "创建成功"),
            @ApiResponse(code = 400, message = "参数验证失败"),
            @ApiResponse(code = 409, message = "账号已存在")
    })
    public ResponseEntity<Students> addStudent(
            @Valid @RequestBody StudentAddDTO studentDTO) {

        Students student = studentsService.addStudent(studentDTO);
        return ResponseEntity.status(HttpStatus.CREATED).body(student);
    }

    @PostMapping("student/delete")
    @ApiOperation(value = "注销学生账号")
    @ApiImplicitParam(name = "bank",type = "String",required = true)
    public String jjD() {
        return "Hello, World!";
    }


}


